/**    
 * @{#} SudoAction.java Create on Apr 2, 2012 8:27:05 PM    
 *    
 * Copyright (c) 2012 by 悠忧虫.    
 *    
 * @author 悠忧虫
 * @version 1.0    
 */
package tk.sunlatus.project.interface4web.action;

import tk.sunlatus.game.sudo.SudoService;
import tk.sunlatus.game.sudo.SudoStruct;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @{# SudoAction.java Create on Apr 2, 2012 8:27:05 PM
 * 
 *     类功能说明: 数独action
 * 
 *     <p>
 *     Copyright: Copyright(c) 2012
 *     </p>
 * @Version 1.0
 * @Author 悠忧虫
 */
public class SudoAction extends ActionSupport {

    /**
     * serialVersionUID：
     */
    private static final long serialVersionUID = 7779399325993073184L;
    private SudoService sudoService = null;
    private SudoStruct sudo = null;
    private int level = 0;
    boolean sudoExist = false;
    private String validateResult = "";

    public String generateSudo() {

        setSudo(sudoService.generateSudo(getLevel()));
        sudoExist = true;
        validateResult = "";
        return SUCCESS;
    }

    public String promt() {
        if (sudo == null) {
            sudo = new SudoStruct();
            return SUCCESS;
        } else if (sudoService == null) {
            return SUCCESS;
        } else if (sudoExist) {
            boolean stepByStepFlag = sudoService.isStepByStepFlag();
            sudoService.setStepByStepFlag(true);
            sudoService.decode(sudo);
            sudoService.setStepByStepFlag(stepByStepFlag);
        }
        validateResult = "";
        return SUCCESS;
    }

    public String decodeSudo() {
        validateResult = "";
        if (sudo == null) {
            sudo = new SudoStruct();
            return SUCCESS;
        } else if (sudoService == null) {
            return SUCCESS;
        } else if (sudoExist) {
            sudoService.decode(sudo);
        }
        return SUCCESS;
    }

    public String validateSudo() {
        if (sudo == null) {
            sudo = new SudoStruct();
            return SUCCESS;
        } else if (sudoService == null) {
            return SUCCESS;
        } else if (sudoExist) {
            validateResult = String.valueOf(sudoService.isValidate(sudo));
        }
        return SUCCESS;

    }

    /**
     * @return the sudoService
     */
    public SudoService getSudoService() {
        return sudoService;
    }

    /**
     * @param sudoService
     *            the sudoService to set
     */
    public void setSudoService(SudoService sudoService) {
        this.sudoService = sudoService;
    }

    /**
     * @return the level
     */
    public int getLevel() {
        return level;
    }

    /**
     * @param level
     *            the level to set
     */
    public void setLevel(int level) {
        this.level = level;
    }

    /**
     * @return the sudo
     */
    public SudoStruct getSudo() {
        return sudo;
    }

    /**
     * @param sudo
     *            the sudo to set
     */
    public void setSudo(SudoStruct sudo) {
        this.sudo = sudo;
    }

    /**
     * @return the validateResult
     */
    public String getValidateResult() {
        return validateResult;
    }

    /**
     * @param validateResult the validateResult to set
     */
    public void setValidateResult(String validateResult) {
        this.validateResult = validateResult;
    }

}
